home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_022 / lemacs / spawn.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  8KB  |  255 lines

  1. /*
  2.  * The routines in this file are called to create a subjob running a command
  3.  * interpreter. This code is a big fat nothing on CP/M-86. You lose.
  4.  */
  5. #include        <stdio.h>
  6. #include    "estruct.h"
  7. #include        "edef.h"
  8.  
  9. #if     AMIGA
  10. #define  NEW   1006
  11. #endif
  12.  
  13. #if     VMS
  14. #define EFN     0                               /* Event flag.          */
  15.  
  16. #include        <ssdef.h>                       /* Random headers.      */
  17. #include        <stsdef.h>
  18. #include        <descrip.h>
  19. #include        <iodef.h>
  20.  
  21. extern  int     oldmode[];                      /* In "termio.c"        */
  22. extern  int     newmode[];                      /* In "termio.c"        */
  23. extern  short   iochan;                         /* In "termio.c"        */
  24. #endif
  25.  
  26. #if     MSDOS & LATTICE
  27. #include        <dos.h>
  28. #undef    CPM
  29. #endif
  30.  
  31. #if     V7
  32. #include        <signal.h>
  33. extern int vttidy();
  34. #endif
  35.  
  36. /*
  37.  * Create a subjob with a copy of the command intrepreter in it. When the
  38.  * command interpreter exits, mark the screen as garbage so that you do a full
  39.  * repaint. Bound to "^X C". The message at the start in VMS puts out a newline.
  40.  * Under some (unknown) condition, you don't get one free when DCL starts up.
  41.  */
  42. spawncli(f, n)
  43. {
  44. #if     AMIGA
  45.         long newcli;
  46.  
  47.         newcli = Open("CON:1/1/639/199/MicroEmacs Subprocess", NEW);
  48.         mlwrite("[Starting new CLI]");
  49.         sgarbf = TRUE;
  50.         Execute("", newcli, 0);
  51.         Close(newcli);
  52.         return(TRUE);
  53. #endif
  54.  
  55. #if     V7
  56.         register char *cp;
  57.         char    *getenv();
  58. #endif
  59. #if     VMS
  60.         movecursor(term.t_nrow, 0);             /* In last line.        */
  61.         mlputs("[Starting DCL]\r\n");
  62.         (*term.t_flush)();                      /* Ignore "ttcol".      */
  63.         sgarbf = TRUE;
  64.         return (sys(NULL));                     /* NULL => DCL.         */
  65. #endif
  66. #if     CPM
  67.         mlwrite("Not in CP/M-86");
  68. #endif
  69. #if     MSDOS & AZTEC
  70.         movecursor(term.t_nrow, 0);             /* Seek to last line.   */
  71.         (*term.t_flush)();
  72.     system("command.com");
  73.         sgarbf = TRUE;
  74.         return(TRUE);
  75. #endif
  76. #if     MSDOS & LATTICE
  77.         movecursor(term.t_nrow, 0);             /* Seek to last line.   */
  78.         (*term.t_flush)();
  79.         sys("\\command.com", "");               /* Run CLI.             */
  80.         sgarbf = TRUE;
  81.         return(TRUE);
  82. #endif
  83. #if     V7
  84.         movecursor(term.t_nrow, 0);             /* Seek to last line.   */
  85.         (*term.t_flush)();
  86.         ttclose();                              /* stty to old settings */
  87.         if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
  88.                 system(cp);
  89.         else
  90. #if    BSD
  91.                 system("exec /bin/csh");
  92. #else
  93.                 system("exec /bin/sh");
  94. #endif
  95.         sgarbf = TRUE;
  96.         sleep(2);
  97.         ttopen();
  98.         return(TRUE);
  99. #endif
  100. }
  101.  
  102. #if    V7 & BSD
  103.  
  104. bktoshell()        /* suspend MicroEMACS and wait to wake up */
  105. {
  106.     int pid;
  107.  
  108.     vttidy();
  109.     pid = getpid();
  110.     kill(pid,SIGTSTP);
  111. }
  112.  
  113. rtfrmshell()
  114. {
  115.     ttopen();
  116.     curwp->w_flag = WFHARD;
  117.     refresh();
  118. }
  119. #endif
  120.  
  121. /*
  122.  * Run a one-liner in a subjob. When the command returns, wait for a single
  123.  * character to be typed, then mark the screen as garbage so a full repaint is
  124.  * done. Bound to "C-X !".
  125.  */
  126. spawn(f, n)
  127. {
  128.         register int    s;
  129.         char            line[NLINE];
  130. #if     AMIGA
  131.         long newcli;
  132.  
  133.         newcli = Open("CON:1/1/639/199/MicroEmacs Subprocess", NEW);
  134.         if ((s=mlreply("CLI command: ", line, NLINE)) != TRUE)
  135.                 return (s);
  136.         Execute(line,0,newcli);
  137.         Close(newcli);
  138.         (*term.t_getchar)();     /* Pause.               */
  139.         sgarbf = TRUE;
  140.         return(TRUE);
  141. #endif
  142. #if     VMS
  143.         if ((s=mlreply("DCL command: ", line, NLINE)) != TRUE)
  144.                 return (s);
  145.         (*term.t_putchar)('\n');                /* Already have '\r'    */
  146.         (*term.t_flush)();
  147.         s = sys(line);                          /* Run the command.     */
  148.         mlputs("\r\n\n[End]");                  /* Pause.               */
  149.         (*term.t_flush)();
  150.         (*term.t_getchar)();
  151.         sgarbf = TRUE;
  152.         return (s);
  153. #endif
  154. #if     CPM
  155.         mlwrite("Not in CP/M-86");
  156.         return (FALSE);
  157. #endif
  158. #if     MSDOS
  159.         if ((s=mlreply("MS-DOS command: ", line, NLINE)) != TRUE)
  160.                 return (s);
  161.         system(line);
  162.         mlputs("\r\n\n[End]");                  /* Pause.               */
  163.         (*term.t_getchar)();     /* Pause.               */
  164.         sgarbf = TRUE;
  165.         return (TRUE);
  166. #endif
  167. #if     V7
  168.         if ((s=mlreply("! ", line, NLINE)) != TRUE)
  169.                 return (s);
  170.         (*term.t_putchar)('\n');                /* Already have '\r'    */
  171.         (*term.t_flush)();
  172.         ttclose();                              /* stty to old modes    */
  173.         system(line);
  174.         sleep(2);
  175.         ttopen();
  176.         mlputs("[End]");                        /* Pause.               */
  177.         (*term.t_flush)();
  178.         while ((s = (*term.t_getchar)()) != '\r' && s != ' ')
  179.                 ;
  180.         sgarbf = TRUE;
  181.         return (TRUE);
  182. #endif
  183. }
  184.  
  185. #if     VMS
  186. /*
  187.  * Run a command. The "cmd" is a pointer to a command string, or NULL if you
  188.  * want to run a copy of DCL in the subjob (this is how the standard routine
  189.  * LIB$SPAWN works. You have to do wierd stuff with the terminal on the way in
  190.  * and the way out, because DCL does not want the channel to be in raw mode.
  191.  */
  192. sys(cmd)
  193. register char   *cmd;
  194. {
  195.         struct  dsc$descriptor  cdsc;
  196.         struct  dsc$descriptor  *cdscp;
  197.         long    status;
  198.         long    substatus;
  199.         long    iosb[2];
  200.  
  201.         status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
  202.                           oldmode, sizeof(oldmode), 0, 0, 0, 0);
  203.         if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
  204.                 return (FALSE);
  205.         cdscp = NULL;                           /* Assume DCL.          */
  206.         if (cmd != NULL) {                      /* Build descriptor.    */
  207.                 cdsc.dsc$a_pointer = cmd;
  208.                 cdsc.dsc$w_length  = strlen(cmd);
  209.                 cdsc.dsc$b_dtype   = DSC$K_DTYPE_T;
  210.                 cdsc.dsc$b_class   = DSC$K_CLASS_S;
  211.                 cdscp = &cdsc;
  212.         }
  213.         status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
  214.         if (status != SS$_NORMAL)
  215.                 substatus = status;
  216.         status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
  217.                           newmode, sizeof(newmode), 0, 0, 0, 0);
  218.         if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
  219.                 return (FALSE);
  220.         if ((substatus&STS$M_SUCCESS) == 0)     /* Command failed.      */
  221.                 return (FALSE);
  222.         return (TRUE);
  223. }
  224. #endif
  225.  
  226. #if    ~AZTEC & MSDOS
  227.  
  228. /*
  229.  * This routine, once again by Bob McNamara, is a C translation of the "system"
  230.  * routine in the MWC-86 run time library. It differs from the "system" routine
  231.  * in that it does not unconditionally append the string ".exe" to the end of
  232.  * the command name. We needed to do this because we want to be able to spawn
  233.  * off "command.com". We really do not understand what it does, but if you don't
  234.  * do it exactly "malloc" starts doing very very strange things.
  235.  */
  236. sys(cmd, tail)
  237. char    *cmd;
  238. char    *tail;
  239. {
  240. #if MWC_86
  241.         register unsigned n;
  242.         extern   char     *__end;
  243.  
  244.         n = __end + 15;
  245.         n >>= 4;
  246.         n = ((n + dsreg() + 16) & 0xFFF0) + 16;
  247.         return(execall(cmd, tail, n));
  248. #endif
  249.  
  250. #if LATTICE
  251.         return forklp(cmd, tail, NULL);
  252. #endif
  253. }
  254. #endif
  255.